package com.vinjogames.gfx;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.PointF;


public class Background {
	
	private Image mBackground;
	private Image mForeground;
	
	private Camera mCamera;
	
	private float mMapWidth;
	private float mMapHeight;
	private PointF mBackOffset;
	private PointF mFrontOffset;
	
	
	public Background(float glWidth, float glHeight, int tileset){
		mMapWidth = glWidth; mMapHeight = glHeight;
		int[] animatedBackgrounds = null;//TODO:
		int[] animatedForegrounds = null;
		mBackground = new Image(animatedBackgrounds[tileset], 
							    Camera.GL_WIDTH*Camera.MAXIMUM_VIEW*1.1f, 
							    Camera.GL_HEIGHT*Camera.MAXIMUM_VIEW*1.1f);
		mForeground = new Image(animatedForegrounds[tileset], 
								Camera.GL_WIDTH*Camera.MAXIMUM_VIEW*1.3f,
								Camera.GL_HEIGHT*Camera.MAXIMUM_VIEW*1.3f);
		
		switch(tileset){
		case 0:
			//GameConVars.GRAPHIC_BACKGROUNDS[0] is animated, so set frames here
			mBackground.setAnimations(new int[]{0,4});
			break;
		case 1:
			break;
		}
		
		mBackOffset = new PointF();
		mFrontOffset = new PointF();
		
		mCamera = Camera.getInstance();
	}

	public void draw(GL10 gl){
		updateOffsets();
		mBackground.draw(gl, mBackOffset, 0);
		long time = 0;
		mForeground.draw(gl, mFrontOffset, time);
	}
	
	private void updateOffsets(){
		mBackOffset.set(mBackground.getWidth()*0.5f + mCamera.getLeftPerc()*(mMapWidth-mBackground.getWidth())
				, mBackground.getHeight()*0.5f + mCamera.getBottomPerc()*(mMapHeight-mBackground.getHeight()));
		mFrontOffset.set(mForeground.getWidth()*0.5f + mCamera.getLeftPerc()*(mMapWidth-mForeground.getWidth())
				, mForeground.getHeight()*0.5f + mCamera.getBottomPerc()*(mMapHeight-mForeground.getHeight()));
	}
}
